home *** CD-ROM | disk | FTP | other *** search
/ PC Home 49 / PC_Home_Issue_49.iso / lldemo / lldemo.shr / ROSETTA.EXE / ROSETTA.DXR / 00604_method scripts.ls < prev    next >
Encoding:
Text File  |  1996-06-24  |  7.6 KB  |  239 lines

  1. global gMethods, gStuMethod
  2.  
  3. on loadMethod thePath
  4.   global gSMSPath, gSlash, gStuInfo
  5.   set gMethods to []
  6.   set theFile to thePath & ".sav"
  7.   set strList to readPropTextFile(theFile)
  8.   if strList = EMPTY then
  9.     return 0
  10.   else
  11.     set gStuMethod to strList
  12.     registerVolume(getaProp(gStuMethod, #volume))
  13.     set theFile to gSMSPath & "methods" & gSlash & getaProp(gStuInfo, #method) & ".met"
  14.     set strList to readPropTextFile(theFile)
  15.     if strList = EMPTY then
  16.       return 0
  17.     else
  18.       set gMethods to strList
  19.       return 1
  20.     end if
  21.   end if
  22. end
  23.  
  24. on saveMethod
  25.   global gSMSStuPath
  26.   set theFile to gSMSStuPath & ".sav"
  27.   if getaProp(gStuMethod, #action) = #inTest then
  28.     setaProp(gStuMethod, #currPageScore, getWholeScore())
  29.     saveRecord()
  30.   else
  31.     setaProp(gStuMethod, #currPageScore, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
  32.   end if
  33.   writePropTextFile(theFile, gStuMethod)
  34. end
  35.  
  36. on saveRecord
  37.   global gMethods, gNewChap, gSMSStuPath, gType, gStartTime
  38.   set newline to RETURN
  39.   set sc to getScore()
  40.   set theRecord to the date & "," & the time & "," & formatTime(the ticks - gStartTime) & "," & getaProp(gMethods, #name) & "," & gNewChap & "," & getaProp(sc, #right) & "," & getaProp(sc, #wrong) & newline
  41.   set theFile to gSMSStuPath & ".rec"
  42.   set theOldRec to readTextFile(theFile)
  43.   if word 1 of theOldRec = "#Error" then
  44.     set oldStuff to EMPTY
  45.   else
  46.     set x to decrypt(theOldRec)
  47.     set oldStuff to x
  48.   end if
  49.   writePropTextFile(theFile, oldStuff & theRecord)
  50. end
  51.  
  52. on getSMSNextMode lastScore
  53.   global gStuInfo, gTest
  54.   set m to getaProp(gStuMethod, #methodList)
  55.   if m = [] then
  56.     if lastScore = #firstTime then
  57.       if getaProp(gStuMethod, #action) = #passed then
  58.         set curr to getaProp(gStuMethod, #unitchap)
  59.         setaProp(gStuMethod, #unitchap, curr + 1)
  60.         if curr < getaProp(gStuInfo, #lastunitchap) then
  61.           set m to createMethodList(getaProp(gMethods, #list), [0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
  62.           setaProp(gStuMethod, #action, #doTest)
  63.         else
  64.           setaProp(gStuMethod, #action, #finished)
  65.         end if
  66.       else
  67.         if getaProp(gStuMethod, #action) = #failed then
  68.           set m to createMethodList(getaProp(gMethods, #list), getaProp(gStuMethod, #currPageScore))
  69.           setaProp(gStuMethod, #action, #doTest)
  70.         else
  71.           if getaProp(gStuMethod, #action) <> #finished then
  72.             set m to createMethodList(getaProp(gMethods, #list), [0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
  73.           end if
  74.         end if
  75.       end if
  76.       setaProp(gStuMethod, #methodList, m)
  77.       setaProp(gStuMethod, #currPageScore, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
  78.     else
  79.     end if
  80.   else
  81.     set tmp to getAt(m, 1)
  82.     if (getaProp(tmp, #redoWrong) = 1) and (lastScore = #wasWrong) then
  83.       set num to count(m)
  84.       set insPoint to 5
  85.       set done to 0
  86.       repeat while done = 0
  87.         if num < insPoint then
  88.           add(m, tmp)
  89.           set done to 1
  90.           next repeat
  91.         end if
  92.         set oneBefore to getAt(m, insPoint - 1)
  93.         set mode to getaProp(oneBefore, #mode)
  94.         if (mode <> "A") and (mode <> "B") and (mode <> "C") then
  95.           addAt(m, insPoint, tmp)
  96.           set done to 1
  97.           next repeat
  98.         end if
  99.         set insPoint to insPoint + 1
  100.       end repeat
  101.     end if
  102.     if lastScore <> #firstTime then
  103.       deleteAt(m, 1)
  104.     end if
  105.     if (lastScore = #firstTime) and (getaProp(gStuMethod, #action) = #inTest) then
  106.       set gTest to 1
  107.       set currPage to getaProp(getAt(getaProp(gStuMethod, #methodList), 1), #page)
  108.       set scores to getaProp(gStuMethod, #currPageScore)
  109.       clearScore()
  110.       repeat with i = 1 to currPage - 1
  111.         set pagescore to getAt(scores, i)
  112.         updateScore(i, pagescore)
  113.         if pagescore <> 10 then
  114.           updateScore(i, pagescore - 10)
  115.         end if
  116.       end repeat
  117.     end if
  118.   end if
  119.   set act to #normal
  120.   set c to count(m)
  121.   if c = 0 then
  122.     if getaProp(gStuMethod, #action) = #doTest then
  123.       setaProp(gStuMethod, #action, #inTest)
  124.       set m to createTestList(getaProp(gMethods, #testMode), getaProp(gMethods, #testBlindfold))
  125.       setaProp(gStuMethod, #methodList, m)
  126.       set next to getaProp(getAt(m, 2), #page)
  127.       set act to #enterTest
  128.       setaProp(gStuMethod, #action, #inTest)
  129.     else
  130.       if getaProp(gStuMethod, #action) = #inTest then
  131.         set sc to getScore()
  132.         set total to getaProp(sc, #right) + getaProp(sc, #wrong)
  133.         set percent to getaProp(sc, #right) * 100 / total
  134.         if percent < getaProp(gStuInfo, #proficiency) then
  135.           setaProp(gStuMethod, #action, #failed)
  136.         else
  137.           setaProp(gStuMethod, #action, #passed)
  138.         end if
  139.         return [#action: #finishedTest]
  140.       else
  141.         if getaProp(gStuMethod, #action) = #finished then
  142.           return [#action: #finishedAll]
  143.         else
  144.           set curr to getaProp(gStuMethod, #unitchap)
  145.           if curr < getaProp(gStuInfo, #lastunitchap) then
  146.             setaProp(gStuMethod, #unitchap, curr + 1)
  147.             return getSMSNextMode(#firstTime)
  148.           end if
  149.           return [#action: #finishedAll]
  150.         end if
  151.       end if
  152.     end if
  153.   else
  154.     if c = 1 then
  155.       set next to 1
  156.     else
  157.       set next to getaProp(getAt(m, 2), #page)
  158.     end if
  159.   end if
  160.   return [#action: act, #unitchap: getaProp(gStuMethod, #unitchap), #page: getaProp(getAt(m, 1), #page), #mode: getaProp(getAt(m, 1), #mode), #blindfold: getaProp(getAt(m, 1), #blindfold), #nextunitchap: getaProp(gStuMethod, #unitchap), #nextPage: next, #language: getaProp(gStuInfo, #language), #allowBrowse: getaProp(getAt(m, 1), #allowBrowse)]
  161. end
  162.  
  163. on createMethodList method, pageScores
  164.   set mlist to []
  165.   set currpos to 1
  166.   set nummodes to count(method)
  167.   set index to []
  168.   repeat with m = 1 to nummodes
  169.     add(index, [#i: getaProp(getAt(method, m), #startPage), #e: getaProp(getAt(method, m), #endPage)])
  170.   end repeat
  171.   repeat while moreToDo(index)
  172.     repeat with m = 1 to nummodes
  173.       set i to getaProp(getAt(index, m), #i)
  174.       if i <> -1 then
  175.         set o to getaProp(getAt(method, m), #offset)
  176.         if currpos >= o then
  177.           set hasPassed to getAt(pageScores, i) = 10
  178.           addmode(mlist, getAt(method, m), i, hasPassed)
  179.           incIdx(getAt(index, m))
  180.         end if
  181.       end if
  182.     end repeat
  183.     set currpos to currpos + 1
  184.   end repeat
  185.   return mlist
  186. end
  187.  
  188. on incIdx index
  189.   set i to getaProp(index, #i)
  190.   set i to i + 1
  191.   if i <= getaProp(index, #e) then
  192.     setaProp(index, #i, i)
  193.   else
  194.     setaProp(index, #i, -1)
  195.   end if
  196. end
  197.  
  198. on moreToDo index
  199.   set num to count(index)
  200.   repeat with i = 1 to num
  201.     if getaProp(getAt(index, i), #i) <> -1 then
  202.       return 1
  203.     end if
  204.   end repeat
  205.   return 0
  206. end
  207.  
  208. on addmode mlist, modeset, i, hasPassed
  209.   if hasPassed = 0 then
  210.     add(mlist, [#page: i, #mode: getaProp(modeset, #mode), #blindfold: getaProp(modeset, #blindfold), #redoWrong: getaProp(modeset, #redoWrong), #allowBrowse: getaProp(modeset, #allowBrowse)])
  211.   end if
  212. end
  213.  
  214. on setTutorial which
  215.   global gStuInfo, gNewChap, gOrder
  216.   if which = 1 then
  217.     set gMethods to value(the text of cast "tutorial 1")
  218.   else
  219.     set gMethods to value(the text of cast "tutorial 2")
  220.   end if
  221.   set gOrder to value(the text of cast "order")
  222.   set idx to mapUC2Index(word 2 of gNewChap)
  223.   setaProp(gStuInfo, #language, ChapStr2Language(gNewChap))
  224.   setaProp(gStuInfo, #proficiency, 0)
  225.   setaProp(gStuInfo, #lastunitchap, idx)
  226.   setaProp(gStuMethod, #unitchap, idx)
  227.   setaProp(gStuMethod, #methodList, [])
  228.   setaProp(gStuMethod, #currPageScore, [])
  229.   setaProp(gStuMethod, #action, #skipTest)
  230. end
  231.  
  232. on createTestList mode, blindfold
  233.   set mlist to []
  234.   repeat with i = 1 to 10
  235.     add(mlist, [#page: i, #mode: mode, #blindfold: blindfold, #redoWrong: 0, #allowBrowse: 0])
  236.   end repeat
  237.   return mlist
  238. end
  239.